package simulation;

import java.util.Iterator;

public class PeekingIterator284  implements Iterator<Integer> {
    Iterator<Integer> iterator;
    boolean b ;
    int bb;
    public PeekingIterator284(Iterator<Integer> iterator) {
        // initialize any member here.
        this.iterator = iterator;
        b = false;
        bb = 0;
    }

    // Returns the next element in the iteration without advancing the iterator.
    public Integer peek() {
        if(b){
            return bb;
        }else {
            b = !b;
            bb = iterator.next();

            return bb;
        }
    }

    // hasNext() and next() should behave the same as in the Iterator interface.
    // Override them if needed.
    @Override
    public Integer next() {
        if(b){
            b=!b;
            return bb;
        }else {
            return iterator.next();
        }
    }

    @Override
    public boolean hasNext() {
        return b||iterator.hasNext();
    }

}
